//This file runs the regressions to produce the plots in figure A7.
*******************************************************************************


//Build Variables for Sun and Abraham

gen decade = .
replace decade = 1  if year == 1974
replace decade = 2  if year == 1982
replace decade = 3  if year == 1992
replace decade = 4  if year == 2002
replace decade = 5  if year == 2012

gen COHORT = TG
replace COHORT =. if Treated == 0



gen rel_time = decade - COHORT 
replace rel_time = 0 if Treated == 0

tab rel_time, gen(RT)



gen CONTROL = 1-Treated



sum RT* if CONTROL ==1

replace RT5 = 0 if CONTROL ==1

//Get estimating sample
reghdfe agpct post offrespop has_c* ,  absorb(ID stateXyear START) cluster(TOWNSHIP)

gen regsamp = e(sample)



*Panel A: No Controls
eventstudyinteract agpct  RT1 RT2 RT3  RT5 RT6 RT7 if regsamp ==1 , absorb(ID stateXyear) cohort(COHORT) control_cohort(CONTROL) vce( cl TOWNSHIP) 

        matrix C = e(b_iw)
        mata st_matrix("A",sqrt(diagonal(st_matrix("e(V_iw)"))))
        matrix C = C \ A'
        matrix list C
		matrix B = C[1...,2..3]
		matrix D = [0\0]
		matrix E = C[1...,4..6]
		matrix F = B,D,E
        coefplot matrix(F[1]), se(F[2]) vertical yline(0, lpattern(dash) lcolor(gs10)) recast(connected) graphregion(color(white)) xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2") xtitle("Time to Treatment") ytitle("Agriculture (%)")

*Panel B: Off-Reservation Population Control
eventstudyinteract agpct  RT1 RT2 RT3  RT5 RT6 RT7 if regsamp ==1 , absorb(ID stateXyear) cohort(COHORT) control_cohort(CONTROL) vce( cl TOWNSHIP) covariates(offrespop)

        matrix C = e(b_iw)
        mata st_matrix("A",sqrt(diagonal(st_matrix("e(V_iw)"))))
        matrix C = C \ A'
        matrix list C
        matrix B = C[1...,2..3]
		matrix D = [0\0]
		matrix E = C[1...,4..6]
		matrix F = B,D,E
        coefplot matrix(F[1]), se(F[2]) vertical yline(0, lpattern(dash) lcolor(gs10)) recast(connected) graphregion(color(white)) xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2") xtitle("Time to Treatment") ytitle("Agriculture (%)")	

	
*Panel C: Casino Control
eventstudyinteract agpct  RT1 RT2 RT3  RT5 RT6 RT7 if regsamp ==1 , absorb(ID stateXyear) cohort(COHORT) control_cohort(CONTROL) vce( cl TOWNSHIP) covariates(has_casino)

        matrix C = e(b_iw)
        mata st_matrix("A",sqrt(diagonal(st_matrix("e(V_iw)"))))
        matrix C = C \ A'
        matrix list C
		matrix B = C[1...,2..3]
		matrix D = [0\0]
		matrix E = C[1...,4..6]
		matrix F = B,D,E
        coefplot matrix(F[1]), se(F[2]) vertical yline(0, lpattern(dash) lcolor(gs10)) recast(connected) graphregion(color(white)) xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2") xtitle("Time to Treatment") ytitle("Agriculture (%)")

	
*Panel D: Credit Access Control
eventstudyinteract agpct  RT1 RT2 RT3  RT5 RT6 RT7 if regsamp ==1 , absorb(ID stateXyear) cohort(COHORT) control_cohort(CONTROL) vce( cl TOWNSHIP) covariates(has_credit)

        matrix C = e(b_iw)
        mata st_matrix("A",sqrt(diagonal(st_matrix("e(V_iw)"))))
        matrix C = C \ A'
        matrix list C
        matrix B = C[1...,2..3]
		matrix D = [0\0]
		matrix E = C[1...,4..6]
		matrix F = B,D,E
        coefplot matrix(F[1]), se(F[2]) vertical yline(0, lpattern(dash) lcolor(gs10)) recast(connected) graphregion(color(white)) xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2") xtitle("Time to Treatment") ytitle("Agriculture (%)")


*Panel E: All Controls
eventstudyinteract agpct  RT1 RT2 RT3  RT5 RT6 RT7 if regsamp ==1 , absorb(ID stateXyear) cohort(COHORT) control_cohort(CONTROL) vce( cl TOWNSHIP) covariates(offrespop has_casino has_credit)

        matrix C = e(b_iw)
        mata st_matrix("A",sqrt(diagonal(st_matrix("e(V_iw)"))))
        matrix C = C \ A'
        matrix list C
        matrix B = C[1...,2..3]
		matrix D = [0\0]
		matrix E = C[1...,4..6]
		matrix F = B,D,E
        coefplot matrix(F[1]), se(F[2]) vertical yline(0, lpattern(dash) lcolor(gs10)) recast(connected) graphregion(color(white)) xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2") xtitle("Time to Treatment") ytitle("Agriculture (%)")


